

jQuery(function ($) {

    function weinxinCode() {
        document.querySelector('.weixinImageUrl').src = host + '/api/weixinpay/generateqrcode?' + longUrl;
        document.querySelector('.weixinImageUrl').onload = function (e) {
            timeone();
            e.stopPropagation();
        };
    }

    //解码
    var para = window.location.search;
    if (para) {
        var param = para.split("&&");
        var order_sn = param[0].split('=')[1];
        var longUrl = param[1];
        $('.order_id').html(order_sn);
        weinxinCode();
        var paramSN = {
            "Order": {
                "order_sn": order_sn
            }
        };
        send_ajax('post', '/get', paramSN, function (data) {
            if (data.code == 200) {
                var price = keepTwoDecimalFull(data.Order.total_amt - data.Order.discount_amt);
                $('.payable').html(price);
            }
        });
    }

    // $('.pc-wrap').click(function () {
    //     alert(23)
    //     window.history.go(-1);
    // });
    //四舍五入
    function keepTwoDecimalFull(num) {
        var result = parseFloat(num);

        if (isNaN(result)) {
            alert('传递参数错误，请检查！');
            return false;
        }

        result = Math.round(num * 100) / 100;

        var s_x = result.toString();
        var pos_decimal = s_x.indexOf('.');
        if (pos_decimal < 0) {
            pos_decimal = s_x.length;
            s_x += '.';
        }
        while (s_x.length <= pos_decimal + 2) {
            s_x += '0';
        }
        return s_x;
    }

    //时间倒计时
    function timeone() {
        var times = 60;
        var timer = setInterval(function () {
            if (times == 0) {
                $('.w_weixinInfo').html("二维码已过期，" + '<a href="javascript:;" class="refresh">\u5237\u65B0</a>' + "页面重新获取二维码。");
                $('.w_weixinInfo').css('color', '#e31613');
                clearInterval(timer);
                $('.refresh').click(function () {
                    weinxinCode();
                });
            } else {
                $('.w_weixinInfo').html("距离二维码过期还剩" + '<span class="y_countdown">' + times + '</span>' + "秒，过期后请刷新页面重新获取二维码。");
                $('.w_weixinInfo').css('color', '#666');
                times--;
            }
        }, 1000);
    }
});